const os = require('os');
const path = require('path');
const fs = require('fs');

export function copy(txt: string) {
    document.addEventListener('copy', function copy(e: any) {
        e.clipboardData.setData('text/plain', txt);
        e.preventDefault();
    })
    document.execCommand('copy');
    document.removeEventListener('copy', copy as any)
}


export function sleep(ms: number) {
    return new Promise(resolve => {
        setTimeout(resolve, ms)
    })
}

export function getDocumentsDir() {
    const homeDir = os.homedir();

    let documentsDir;

    switch (process.platform) {
        case 'win32':
            documentsDir = path.join(homeDir, 'Documents');  // Windows 平台
            break;
        case 'darwin':
            documentsDir = path.join(homeDir, 'Documents');  // macOS 平台
            break;
        case 'linux':
            documentsDir = path.join(homeDir, 'Documents');  // 大多数 Linux 发行版
            break;
        default:
            throw new Error('Unsupported platform');
    }
    documentsDir+= "/.beconsole";
    if(!fs.existsSync(documentsDir)) {
        fs.mkdirSync(documentsDir, { recursive: true });
    }
    return documentsDir;
}
